<template>
  <Spin :spinning="loading1" tip="Loading...">
    <div>
      <!-- 备件保修类型查询 -->
      <TopFilter ref="TopFilterss" :list="topFilterInit" :cols="3" :collapse="collapse" labelWidth="90" @filterChange="changeHandle"></TopFilter>
      <!-- table -->
      <Spin :spinning="loading" tip="导入中，请稍后...">
        <FilterTable
          ref="table"
          :columns="columns"
          :params="fetchParams"
          :fetchapi="fetchapi"
          :datakey="'records'"
          :onColumnsChange="(columns) => (this.columns = columns)"
          :onRowSelectChange="selectChange"
        >
        </FilterTable>
      </Spin>
      <BaseDialog :visible.sync="visible" :title="'备件保修类型明细'" width="850px" destroyOnClose
        :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
        <EditForm :rowData="rowData" @close="editclose" @save="editsave"></EditForm>
      </BaseDialog>
    </div>
  </Spin>
</template>
<script>
import { getToken, getAppId, getUserId } from '@/assets/js/auth';
import EditForm from './editForm.vue';
import { getListByPage } from '@/api/claim/factory/PartWarrantyType/index.js';
import {dictionary} from'@/utils/dictMixin';
export default {
  props: {
    // rowData: {
    //   type: Object,
    //   default: () => ({})
    // }
  },
  mixins: [dictionary],
  components: {
    EditForm,
  },
  data() {
    return {
      dataList: [],
      rowData: {},
      params: {},
      visible: false,
      disableds: true,
      showImport: false,
      //collapse: false,  //收起显示与否
      visibleEdit: false,
      fetchapi: getListByPage,
      topFilterInit: this.topFilterInitFun(),
      columns: this.creatHeader(),
      fetchParams: {}, //ipa 接口
      selectedRows: [], //选中经销商
      dialogTitle: '选择车辆',
      visibleAdd: false,
      headersObj: {
        jwt: getToken(),
        appId: getAppId(),
        userId: getUserId(),
        userAgent: 'pc',
      },
      loading: false,
      loading1: false,
      fileList: [],
    };
  },
  created() {
    // this.chuqi();
    // if(getAppId()=='beijing'){
    //   this.topFilterInit.find((x) => x.fieldName == 'powerType').itemList = this.createDictList('6008');
    // }else{
    //   this.topFilterInit.find((x) => x.fieldName == 'powerType').itemList = this.createDictList('6008');
    //   this.topFilterInit.find((x) => x.fieldName == 'powerType').initialValue = 60081002;
    //   this.topFilterInit.find((x) => x.fieldName == 'powerType').disabled=true;

    // }
  },
  methods: {
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      this.disableds = this.selectedRows.length <= 0;
      console.log(this.selectedRows);
    },
    editclose() {
      this.visible = false;
    },
    emitFun(val) {
      this.rowData = val;
      this.visible = true;
    },
    editsave() {
      this.visible = false;
      this.fetchParams = { ...this.fetchParams };
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = Object.assign({}, this.fetchParams, val);
      console.log(val);
    },
    //搜索数据
    topFilterInitFun() {
      // 备件代码、备件名称、备件类型、、是否特批、是否辅料、是否附件、是否停用
      return [
        {
          type: 'INPUT',
          label: '备件代码',
          fieldName: 'partCode',
          placeholder: '请输入',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '备件名称',
          fieldName: 'partName',
          placeholder: '请输入.',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '采购渠道代码',
          fieldName: 'channelCode',
          placeholder: '请输入采购渠道代码...',
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '采购渠道名称',
          fieldName: 'channelName',
          placeholder: '请输入采购渠道名称...',
          initialValue: '',
        },
        {
          type: 'SELECT',
          label: '备件类型',
          fieldName: 'warrantyType',
          placeholder: '请选择',
          initialValue: '',
          filterable: true,
          itemList: this.createDictList('5509')
        },
        {
          type: 'SELECT',
          label: '返件类型',
          fieldName: 'returnType',
          placeholder: '请选择...',
          initialValue: '',
          filterable: true,
          itemList: this.createDictList('5585', [55851002])
        },
        {
          type: 'SELECT',
          label: '是否特批',
          placeholder: '请选择...',
          fieldName: 'isSpecially',
          itemList: this.createDictList('1004')
        },
        {
          type: 'SELECT',
          label: '是否辅料',
          placeholder: '请选择...',
          fieldName: 'isAccessories',
          itemList: this.createDictList('1004')
        },
        {
          type: 'SELECT',
          label: '是否附件',
          placeholder: '请选择...',
          fieldName: 'isAttached',
          itemList: this.createDictList('1004')
        },
        {
          type: 'SELECT',
          label: '状态',
          placeholder: '请选择...',
          fieldName: 'ptStatus',
          itemList: [
            { text: '启用', value: 10041001 },
            { text: '停用', value: 10041002 }
          ],
        },
        {
          type: 'SELECT',
          label: '是否报废',
          fieldName: 'isScrap',
          initialValue: '',
          itemList: [
            { text: '是', value: 10041001 },
            { text: '否', value: 10041002 }
          ],
         },
        /* {
          type: 'SELECT',
          label: '是否停用',
          placeholder: '请选择...',
          fieldName: 'isDeleted',
          itemList: this.createDictList('1004')
        }, */
      ];
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          fixed: 'left',
          sorter: true,
          render: (props) => {
            return <span>{props.row.index + 1}</span>;
          },
        },
        {
          title: '操作',
          width: 100,
          dataIndex: 'column-action',
          render: (props, h) => {
            return (
              <div style="text-align:center">
                <multiuse-button size="mini" type="text" onClick={() => this.emitFun(props.row)} >
                  明细
                </multiuse-button>
              </div>
            );
          }
        },
        // 备件代码、备件名称、供应商编码（取值：备件主数据）、备件类型、是否特批、返件类型、是否辅料、是否附件、适用车系、创建人、创建时间、修改人、修改时间
        { title: '备件代码', dataIndex: 'partCode', sorter: true, width: 180 },
        { title: '备件名称', dataIndex: 'partName', sorter: true , width: 180 },
        { title: '索赔价', dataIndex: 'claimPrice', sorter: true },
        { title: '索赔价生效日期', dataIndex: 'claimPriceDate', sorter: true },
        { title: '备件管理费率%', dataIndex: 'manageRate', sorter: true , render: (props) => {
            return <span>{parseFloat(props.row.manageRate * 100).toFixed(2)}</span>;
          },},
        { title: '采购渠道代码', dataIndex: 'channelCode', sorter: true },
        { title: '采购渠道名称', dataIndex: 'channelName', sorter: true,width: 200  },
        { title: '供应商编码', dataIndex: 'supplierCode', sorter: true },
        { title: '备件类型', dataIndex: 'warrantyType', sorter: true ,dictItems: this.createDictList('5509') },
        { title: '是否特批', dataIndex: 'isSpeciallyStr', sorter: true, width: 120 },
        { title: '返件类型', dataIndex: 'returnType', sorter: true, width: 120 , dictItems: this.createDictList('5585', [55851002]) },
        { title: '是否辅料', dataIndex: 'isAccessoriesStr', sorter: true, width: 120 },
        { title: '是否附件', dataIndex: 'isAttachedStr', sorter: true, width: 120 },
        { title: '适用车型', dataIndex: 'series', sorter: true },
        { title: '状态', dataIndex: 'ptStatusStr', sorter: true },
        { title: '是否报废', dataIndex: 'isScrap', sorter: true,dictItems: [
            { text: '是', value: 10041001 },
            { text: '否', value: 10041002 },
          ],
        },
      /*   { title: '创建人', dataIndex: 'createdBy', sorter: true },
        { title: '创建时间', dataIndex: 'createdAt', sorter: true, width: 220 }, */
        { title: '修改人', dataIndex: 'updatedBy', sorter: true },
        { title: '修改时间', dataIndex: 'updatedAt', sorter: true, width: 220 }
      ];
    },
  },
};
</script>

<style lang="less" scoped></style>
